import java.util.LinkedHashMap;

/*
 * @lc app=leetcode.cn id=146 lang=java
 *
 * [146] LRU 缓存
 */

// @lc code=start
class LRUCache {
    int cap;
    LinkedHashMap<Integer, Integer> cache = new LinkedHashMap<>(1 << 4, 0.75f, true);

    public LRUCache(int capacity) {
        cap = capacity;
    }

    public int get(int key) {
        return cache.getOrDefault(key, -1);
    }

    public void put(int key, int value) {
        cache.put(key, value);
        if (cache.size() > cap) {
            cache.remove(cache.entrySet().iterator().next().getKey());
        }
    }
    /**
     * ["LRUCache","get","put","get","put","put","get","get"]
     * [[2],[2], [2,6],[1], [1,5], [1,2],[1],[2]]
     */
}

/**
 * Your LRUCache object will be instantiated and called as such:
 * LRUCache obj = new LRUCache(capacity);
 * int param_1 = obj.get(key);
 * obj.put(key,value);
 */
// @lc code=end
